package com.ip.pojo.common;

import com.ip.pojo.enums.ResponseCodeEnum;
import lombok.Data;

@Data
public class ResponseEntity<T> {
    private int code;
    private String msg;

    private T data;

    public static ResponseEntity<String> success() {
        ResponseEntity<String> entity = new ResponseEntity<>();
        entity.setCode(ResponseCodeEnum.OK.getCode());
        entity.setData("ok");
        return entity;
    }

    public static <T> ResponseEntity<T> success(T data) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setCode(ResponseCodeEnum.OK.getCode());
        entity.setData(data);
        return entity;
    }

    public static <T> ResponseEntity<T> failed(ResponseCodeEnum errorCode) {
        ResponseEntity<T> entity = new ResponseEntity<>();
        entity.setCode(errorCode.getCode());
        entity.setMsg(errorCode.getMsg());
        return entity;
    }
}
